package 力扣;

/**
 * @author yyq
 * @create 2022-04-19 10:43
 */
public class leetcode701 {

    public TreeNode insertIntoBST(TreeNode root, int val) {
        if(root==null) return new TreeNode(val);
        preOrder(root,val);
        return root;
    }

    private void preOrder(TreeNode root, int val) {
        if(root.val>val&&root.left==null){
            root.left=new TreeNode(val);
        }
        if(root.val<val&&root.right==null){
            root.right=new TreeNode(val);
        }

        if(root.val>val&&root.left!=null){
            insertIntoBST(root.left,val);
        }
        if(root.val<val&&root.right!=null){
            insertIntoBST(root.right,val);
        }
    }

}
